package ru.apertum.qsystem.client.forms;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static ru.apertum.qsystem.common.Uses.PATTERN_URL;

public class FIndicatorBoardTest {
    String pattern;
    Pattern replace;

    @BeforeTest
    public void setUp() {
        pattern = PATTERN_URL;
        replace = Pattern.compile(pattern);
    }

    @Test
    public void testUrlMatcherNo1() {
        String txt = "Asd asda sd.";
        Matcher matcher = replace.matcher(txt);
        assertFalse(matcher.matches());
    }

    @Test
    public void testUrlMatcherIpPort() {
        String txt = "https://123.321.213.54:8080";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherIpPort2() {
        String txt = "https://123.321.213.54:8080&param=value";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherYa() {
        String txt = "http://ya.ru";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherYas() {
        String txt = "https://ya.ru";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherYa3() {
        String txt = "http://ya.ru/";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherYa2() {
        String txt = "http://alisa.ya.ru";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherEng() {
        String txt = "http://192.168.88.3:8081/asd/template.html#";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherRus() {
        String txt = "http://192.168.88.3:8081/Вы-ше_сто/ящие/рус.ру";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }

    @Test
    public void testUrlMatcherRusSp() {
        String txt = "http://192.168.88.3:8081/Вышестоящие и контролирующие органы/template.html";
        Matcher matcher = replace.matcher(txt);
        assertTrue(matcher.matches());
    }
}